package com.lyh.web.controller.app;

import java.math.BigDecimal;
import java.util.AbstractMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lyh.system.mapper.AssetEvidenceMapper;
import org.apache.poi.hpsf.Decimal;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lyh.common.annotation.Log;
import com.lyh.common.core.controller.BaseController;
import com.lyh.common.core.domain.AjaxResult;
import com.lyh.common.enums.BusinessType;
import com.lyh.system.domain.AssetEvidence;
import com.lyh.system.service.IAssetEvidenceService;
import com.lyh.common.utils.poi.ExcelUtil;
import com.lyh.common.core.page.TableDataInfo;

/**
 * 资产通证Controller
 *
 * @author ruoyi
 * @date 2023-04-27
 */
@RestController
@RequestMapping("/app/evidence")
public class AssetEvidenceController extends BaseController {
    @Autowired
    private IAssetEvidenceService assetEvidenceService;
    @Autowired
    private AssetEvidenceMapper assetEvidenceMapper;

    /**
     * 查询资产通证列表
     */
//    @PreAuthorize("@ss.hasPermi('system:evidence:list')")
    @GetMapping("/list")
    public AjaxResult list() {
        QueryWrapper<AssetEvidence> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("use_flag",1);
        List<AssetEvidence> list = assetEvidenceMapper.selectList(queryWrapper);
        return AjaxResult.success(list);
    }

    /**
     * 查询资产通证列表,不分页
     */
    @GetMapping("/allList")
    public AjaxResult allList(AssetEvidence assetEvidence) {
        List<AssetEvidence> list = assetEvidenceService.selectAssetEvidenceList(assetEvidence);
        return AjaxResult.success(list);
    }

    /**
     * 导出资产通证列表
     */
    @PreAuthorize("@ss.hasPermi('system:evidence:export')")
    @Log(title = "资产通证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetEvidence assetEvidence) {
        List<AssetEvidence> list = assetEvidenceService.selectAssetEvidenceList(assetEvidence);
        ExcelUtil<AssetEvidence> util = new ExcelUtil<AssetEvidence>(AssetEvidence.class);
        util.exportExcel(response, list, "资产通证数据");
    }

    /**
     * 获取资产通证详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:evidence:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(assetEvidenceService.selectAssetEvidenceById(id));
    }

    /**
     * 新增资产通证
     */
    @PreAuthorize("@ss.hasPermi('system:evidence:add')")
    @Log(title = "资产通证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetEvidence assetEvidence) {
        return toAjax(assetEvidenceService.insertAssetEvidence(assetEvidence));
    }

    /**
     * 修改资产通证
     */
    @PreAuthorize("@ss.hasPermi('system:evidence:edit')")
    @Log(title = "资产通证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetEvidence assetEvidence) {
        return toAjax(assetEvidenceService.updateAssetEvidence(assetEvidence));
    }

    /**
     * 删除资产通证
     */
    @PreAuthorize("@ss.hasPermi('system:evidence:remove')")
    @Log(title = "资产通证", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(assetEvidenceService.deleteAssetEvidenceByIds(ids));
    }
}
